
(function(){
	var app = angular.module('myApp',[]);
	
		app.directive('homectrl', function($compile){
		    var linkFn = function(scope, element, attrs){        
		        var addDiv = function(e){
		            e.preventDefault();
		            $.get("htc/main.html?uid="+uniqueId()).success(function(data) {
			    		 var compiledHtml = $compile(data)(scope);
			             $('#place0').html(compiledHtml);
		         	});
		            loadcontrol(0);
		        };
		  
		        $('homeCtrl').on('click', addDiv);
		    };
		    return {
		        restrict: 'E',
		        template: 'Home',
		        link: linkFn
		    };
		});

		app.directive('examctrl', function($compile){
		    var linkFn = function(scope, element, attrs){        
		        var addDiv = function(e){
		            e.preventDefault();
		            $.get("htc/question.html?uid="+uniqueId()).success(function(data) {
			    		 var compiledHtml = $compile(data)(scope);
			             $('#place1').html(compiledHtml);
		         	});
		            loadcontrol(1);
		        };
		  
		        $('examctrl').on('click', addDiv);
		    };
		    return {
		        restrict: 'E',
		        template: 'Exam',
		        link: linkFn
		    };
		});
		
		app.directive('signinctrl', function($compile){
		    var linkFn = function(scope, element, attrs){        
		        var addDiv = function(e){
		            e.preventDefault();
		            $.get("htc/login.html?uid="+uniqueId()).success(function(data) {
			    		 var compiledHtml = $compile(data)(scope);
			             $('#place2').html(compiledHtml);
		         	});
		            loadcontrol(2);
		           
		        };
		        $('signinctrl').on('click', addDiv);
		    };
		    return {
		        restrict: 'E',
		        template: 'Sign In',
		        link: linkFn
		    };
		});
		

		
		app.directive('listctrl', function($compile){
		    var linkFn = function(scope, element, attrs){        
		        var addDiv = function(e){
		            e.preventDefault();
		            $.get("htc/list.html?uid="+uniqueId()).success(function(data) {
			    		 var compiledHtml = $compile(data)(scope);
			             $('#place3').html(compiledHtml);
		         	});
		            loadcontrol(3);
		        };
		  
		        $('listctrl').on('click', addDiv);
		    };
		    return {
		        restrict: 'E',
		        template: 'MyList',
		        link: linkFn
		    };
		});
		
		app.directive('aboutusctrl', function($compile){
		    var linkFn = function(scope, element, attrs){        
		        var addDiv = function(e){
		            e.preventDefault();
		            $.get("htc/aboutus.html?uid="+uniqueId()).success(function(data) {
			    		 var compiledHtml = $compile(data)(scope);
			             $('#place3').html(compiledHtml);
		         	});
		            loadcontrol(4);
		        };
		  
		        $('aboutusctrl').on('click', addDiv);
		    };
		    return {
		        restrict: 'E',
		        template: 'AboutUs',
		        link: linkFn
		    };
		});
		
		menuLevel2(app);
})();


function loadcontrol(step){
	var p = $( "#page-content-wrapper" );
	var position = p.offset();
	var width= p.width() - 54;
	$('#box' + document.getElementById("stepvalue").value).animate({ 'top': '-1500px','left': position.left, 'width':'1000px' },1000);
	$('#stepvalue').val(step);
    $('#box' + ($('#stepvalue').val())).animate({ 'left': position.left}, 1);
    $('#box' + ($('#stepvalue').val())).animate({ 'left': position.left,'top': '0px', 'width':'1000px'}, 1000);
}

function menuLevel2(app){
	
	app.directive('businessmenu', function($compile){
	    var linkFn = function(scope, element, attrs){        
	        var addDiv0 = function(e){
	        	e.preventDefault();
	            $.get("htc/enterabusiness.html?uid="+uniqueId()).success(function(data) {
		    		 var compiledHtml = $compile(data)(scope);
		             $('#place2').html(compiledHtml);
	         	});
	            loginclick();
	        };
	        $('businessmenu').on('click', addDiv0);
	        attrs.$$element.hide();
	    };
	    return {
	        restrict: 'E',
	        template: 'Business',
	        link: linkFn
	    };
	});
	
	app.directive('categorymenu', function($compile){
	    var linkFn = function(scope, element, attrs){        
	        var addDiv0 = function(e){
	            e.preventDefault();
	            $.get("htc/category.html?uid="+uniqueId()).success(function(data) {
		    		 var compiledHtml = $compile(data)(scope);
		             $('#place2').html(compiledHtml);
	         	});
	            categoryclick();
	        };
	        $('categorymenu').on('click', addDiv0);
	        attrs.$$element.hide();
	    };
	    return {
	        restrict: 'E',
	        template: 'category',
	        link: linkFn
	    };
	});
	
	app.directive('newsmenu', function($compile){
	    var linkFn = function(scope, element, attrs){ 
	        var addDiv0 = function(e){
	            e.preventDefault();
	            $.get("htc/news.html?uid="+uniqueId()).success(function(data) {
		    		 var compiledHtml = $compile(data)(scope);
		             $('#place2').html(compiledHtml);
	         	});
	            newsclick();
	        };
	  
	        $('newsmenu').on('click', addDiv0);
	        attrs.$$element.hide();
	    };
	    return {
	        restrict: 'E',
	        template: 'News',
	        link: linkFn
	    };
	});
	
	app.directive('couponmenu', function($compile){
	    var linkFn = function(scope, element, attrs){        
	        var addDiv0 = function(e){
	            e.preventDefault();
	            $.get("htc/coupon.html?uid="+uniqueId()).success(function(data) {
		    		 var compiledHtml = $compile(data)(scope);
		             $('#place2').html(compiledHtml);
	         	});
	            couponclick();
	        };
	        $('couponmenu').on('click', addDiv0);
	        attrs.$$element.hide();
	    };
	    return {
	        restrict: 'E',
	        template: 'Coupon',
	        link: linkFn
	    };
	});
}

function loginclick(){
		var content = $("#place2");
	    angular.element(document).injector().invoke(function($compile) {
	    	$.get("htc/enterabusiness.html?uid="+uniqueId()).success(function(data) {
	    		var scope = angular.element(content).scope();
	      		 var compiledHtml = $compile(data)(scope);
	               $('#place2').html(compiledHtml);
	               $('#btnSubmit').on('click', function(data){
	            	   var scope = angular.element($(".ng-scope")).scope(0);
	            	   insertBusiness(scope);
	            	});
	       	});
	    });
}


function categoryclick(){
	var content = $("#place2");
    angular.element(document).injector().invoke(function($compile) {
    	$.get("htc/category.html?uid="+uniqueId()).success(function(data) {
    		var scope = angular.element(content).scope();
      		 var compiledHtml = $compile(data)(scope);
               $('#place2').html(compiledHtml);
               $('#btnSubmit').on('click', function(data){
            	   var scope = angular.element($(".ng-scope")).scope(0);
            	   insertCategory(scope);
            	});
       	});
    });
}

function couponclick(){
	var content = $("#place2");
    angular.element(document).injector().invoke(function($compile) {
    	$.get("htc/coupon.html?uid="+uniqueId()).success(function(data) {
    		var scope = angular.element(content).scope();
      		 var compiledHtml = $compile(data)(scope);
               $('#place2').html(compiledHtml);
               $('#btnSubmit').on('click', function(data){
            	   var scope = angular.element($(".ng-scope")).scope(0);
            	   insertCoupon(scope);
            	});
       	});
    });
}

function newsclick(){
	var content = $("#place2");
    angular.element(document).injector().invoke(function($compile) {
    	$.get("htc/news.html?uid="+uniqueId()).success(function(data) {
    		var scope = angular.element(content).scope();
      		 var compiledHtml = $compile(data)(scope);
               $('#place2').html(compiledHtml);
               $('#btnSubmit').on('click', function(data){
            	   var scope = angular.element($(".ng-scope")).scope(0);
            	   insertNews(scope);
            	});
       	});
    });
}

function setModel(){
	var app = angular.module('myApp',[]);
	app.directive('dateselect', function () {
		return {
		    restrict: 'E',
		    transclude: true,
		    scope:{
		        bindModel:'=ngModel'
		    },
		    template:'<input ng-model="bindModel"/>'
		}
	});
}



